import axios from 'axios'
import { Toast } from 'vant'

// eslint-disable-next-line no-undef
const baseUrl = '/' // 接口前缀

// 创建axios实例
const service = axios.create({
  // baseURL: baseUrl,
  timeout: 60000 // 请求超时时间
})

// request拦截器
service.interceptors.request.use(config => {
  return config
}, error => {
  // Do something with request error
  console.log(error) // for debug
  Promise.reject(error)
})

// respone拦截器
service.interceptors.response.use(
  response => {
    return response.data.result
  },
  error => {
    Toast(error.response.data.msg)
    return Promise.reject(error)
  }
)

export default service
